<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>登录页面</title>
    <script type="text/javascript" src="js/jquery.2.1.4.js"></script>
</head>
<body>

<c:if test="${sessionScope.user!=null}">
    <c:redirect url="/list"/>
</c:if>

<fieldset style="width:350px; margin: 50px auto">
    <legend>请登录</legend>
    <form action="/jdbcmvc/loginuser" method="post">
        <br> 用户名：<input id="username" type="text" name="username">
        <span id="tag1" style="color: red"></span> <br><br>
        密&nbsp;&nbsp;&nbsp;码：<input id="pwd" type="password" name="pwd">
        <span id="tag2" style="color: red"></span><br><br>
        <input type="button" value="登录" onclick="login();"/>&nbsp;&nbsp;&nbsp;
        <input type="button" value="注册" onclick="regist();">
        <span id="tag3" style="color: red">${dis}</span>
    </form>
</fieldset>
</body>
<script>
    function regist() {
        window.location.href = "/jdbcmvc/regist.jsp";
    }

    function login() {
        var flag = true;
        $("#tag1").html("");
        $("#tag2").html("");
        $("#tag3").html("");
        if ($("#username").val().trim() == "") {
            $("#tag1").html("用户名不能为空");
            flag = false;
        }
        if ($("#pwd").val().trim() == "") {
            $("#tag2").html("密码不能为空");
            flag = false;
        }
        if (flag) {
            var username = $("#username").val();
            var pwd = $("#pwd").val();
            $.post("loginuser", {username: username, pwd: pwd}, function (data) {
                if (data == 1) {
                    window.location.href = "/jdbcmvc/list";
                } else {
                    $("#tag3").html("用户名或密码错误");
                }
            });
        }
    }

    /*function login() {
        flag = false;
        document.getElementById("tag1").innerHTML=""
        document.getElementById("tag2").innerHTML=""
        document.getElementById("tag3").innerHTML=""
        if (document.getElementById("username").value==""){
            document.getElementById("tag1").innerHTML="用户名不能为空"
            flag = true;
        }
        if (document.getElementById("password").value==""){
            document.getElementById("tag2").innerHTML="密码不能为空"
            flag = true;
        }
        if (flag){
            return false;
        }
    }*/
</script>
</html>
